package com.capgemini.remind.controller;

import com.capgemini.core.AjaxResponse;
import com.capgemini.interceptor.DealerNumUtils;
import com.capgemini.remind.pojo.DealerPromotionPrivilege;
import com.capgemini.remind.service.CommonsService;
import com.capgemini.remind.service.DealerPromotionPrivilegeService;
import com.capgemini.remind.service.RemindService;
import com.capgemini.remind.service.RemindSmsService;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Calendar;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/remind/report")
public class RemindReportController {
	// 日志记录器
	public final Logger log = LoggerFactory.getLogger(this.getClass());
	@Autowired
	private RemindService remindService;
	@Autowired
	private RemindSmsService remindSmsService;
	@Autowired
	private CommonsService commonsService;

	@RequestMapping("/manage/{dealerNum}")
	public Object manage(@PathVariable("dealerNum") String dealerNum) {

		ModelAndView mv = new ModelAndView("/remind/remindReport.jsp");

		mv.addObject("dealerNum", DealerNumUtils.getDealerNum());

//		Long smsQuantity = remindSmsService.querySmsQuantityByDealerNum(dealerNum);
		Long smsQuantity = null;
		mv.addObject("smsQuantity", smsQuantity);

		//当前月份
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.MONTH, -1);
		mv.addObject("preMonth", DateFormatUtils.format(calendar, "yyyy-MM"));
		mv.addObject("currentMonth", DateFormatUtils.format(Calendar.getInstance(), "yyyy-MM"));

		//保养项目
		List<String> serviceRemindItems = commonsService.queryByCodeValueGroupByType("ServiceRemindEnabled");
		mv.addObject("serviceRemindItems", serviceRemindItems);

		return mv;
	}

	@RequestMapping("/load/send")
	@ResponseBody
	public Object loadSendData(@RequestParam Map param) {
		AjaxResponse ajaxResponse = new AjaxResponse();

		ajaxResponse.setData(remindService.getRemindReportForSend(param));

		return ajaxResponse;
	}

	@RequestMapping("/load/notsend")
	@ResponseBody
	public Object loadNotSendData(@RequestParam Map param) {
		AjaxResponse ajaxResponse = new AjaxResponse();

		ajaxResponse.setData(remindService.getRemindReportForNotSend(param));

		return ajaxResponse;
	}


}
